| Conditions | 1 |
| Paths | 4 |
| Total Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | (function($) { |
||
| 17 | init: function() { |
||
| 18 | this.parentElement = jQuery('#Root_Pricing') |
||
| 19 | var countryCurrencies = jQuery.parseJSON(jQuery(UpdatePrices.parentElement).find('[name=CountryCurrencies]').val()); |
||
| 20 | var fromField = jQuery(UpdatePrices.parentElement).find('#From select'); |
||
| 21 | var toField = jQuery(UpdatePrices.parentElement).find('#To'); |
||
| 22 | |||
| 23 | jQuery(fromField).change( |
||
| 24 | function() { |
||
| 25 | var code = jQuery(this).val(); |
||
| 26 | var countries = new Array(); |
||
| 27 | if(code in countryCurrencies) { |
||
| 28 | var currency = countryCurrencies[code]; |
||
| 29 | jQuery.each(countryCurrencies, function(countryCode, countryCurrency) { |
||
| 30 | if(countryCurrency == currency && countryCode != code) { |
||
| 31 | countries.push(countryCode); |
||
| 32 | } |
||
| 33 | }); |
||
| 34 | } |
||
| 35 | jQuery(toField).find('li').hide(); |
||
| 36 | jQuery(toField).find(':checkbox').attr('checked', false); |
||
| 37 | for(i = 0; i < countries.length; i++) { |
||
| 38 | jQuery(toField).find('li.val' + countries[i]).show(); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | ); |
||
| 42 | jQuery(fromField).change(); |
||
| 43 | |||
| 44 | jQuery(this.parentElement).find('#UpdatePriceLink a').click( |
||
| 45 | function(event) { |
||
| 46 | var fromCountry = jQuery(fromField).val(); |
||
| 47 | var toCountries = jQuery(toField).find(':checkbox:checked'); |
||
| 48 | if(fromCountry && jQuery(toCountries).length > 0) { |
||
| 49 | var confirmation = confirm('Are you sure that you want to copy those prices over ?'); |
||
| 50 | if(confirmation) { |
||
| 51 | toCountries = jQuery.map(toCountries, function(element) { |
||
| 52 | return jQuery(element).attr('value'); |
||
| 53 | }); |
||
| 54 | toCountries.join(','); |
||
| 55 | var link = jQuery(this).attr('href'); |
||
| 56 | link += '&' + jQuery(fromField).attr('name') + '=' + jQuery(fromField).val(); |
||
| 57 | link += '&' + jQuery(toField).attr('id') + '=' + toCountries; |
||
| 58 | alert(link); |
||
| 59 | jQuery(this).attr('href', link); |
||
| 60 | return true; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | event.preventDefault(); |
||
| 64 | return false; |
||
| 65 | } |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | } |
||
| 70 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.